#include <iostream>
#include <vector>
#include <deque>

int n, r, c, w, x1, y1, x2, y2;
int M;
std::vector<std::vector<int>> id[17]; // down right corner
int ID(int l, int i, int j) {
  if (0 <= i && i < int(id[l].size()) && 0 <= j && j < int(id[l][0].size())) {
    return id[l][i][j];
  }
  return -1;
}
std::vector<std::vector<std::pair<int, int>>> E;
void addedge(int u, int v, int w) {
  if (v != -1) {
    E[u].push_back({v, w});
    ++M;
  }
}
void add_n(int u, int i, int j) {
  addedge(u, ID(w, i + n - 1, j + n - 1), 1);
  addedge(u, ID(w, i + n - 1, j - n + (1 << w)), 1);
  addedge(u, ID(w, i - n + (1 << w), j + n - 1), 1);
  addedge(u, ID(w, i - n + (1 << w), j - n + (1 << w)), 1);
}

std::string pr[6000007];
std::vector<int> dis;

int main() {
  std::freopen("stamp.in", "r", stdin);
  std::freopen("stamp.out", "w", stdout);
  std::cin.tie(nullptr)->sync_with_stdio(false);
  std::cin >> r >> c >> n >> x1 >> y1 >> x2 >> y2;
  for (int i = 0; i < r; ++i) {
    id[0].push_back(std::vector<int>(c));
    for (int j = 0; j < c; ++j) {
      id[0][i][j] = E.size();
      E.push_back({});
    }
  }
  for (int l = 1; (1 << l) <= 2 * n - 1; ++l) {
    for (int i = 0; i < r + (1 << l) - 1; ++i) {
      id[l].push_back(std::vector<int>(c + (1 << l) - 1));
      for (int j = 0; j < c + (1 << l) - 1; ++j) {
        id[l][i][j] = E.size();
        E.push_back({});
        addedge(id[l][i][j], ID(l - 1, i, j), 0);
        addedge(id[l][i][j], ID(l - 1, i, j - (1 << (l - 1))), 0);
        addedge(id[l][i][j], ID(l - 1, i - (1 << (l - 1)), j), 0);
        addedge(id[l][i][j], ID(l - 1, i - (1 << (l - 1)), j - (1 << (l - 1))), 0);
      }
    }
    w = l;
  }
  for (int i = 0; i < r; ++i) {
    for (int j = 0; j < c; ++j) {
      add_n(id[0][i][j], i, j - 1);
      add_n(id[0][i][j], i, j + 1);
      add_n(id[0][i][j], i - 1, j);
      add_n(id[0][i][j], i + 1, j);
    }
  }
  for (int i = 0; i < r; ++i) {
    // pr[i] = std::string(c, '.');
    std::cin >> pr[i];
  }
  for (int i = 0; i < r; ++i) {
    for (int j = 0; j < c; ++j) {
      for (auto [x, y] : std::vector<std::pair<int, int>>{{0, -1}, {0, +1}, {-1, 0}, {+1, 0}}) {
        x += i, y += j;
        if (0 <= x && x < r && 0 <= y && y < c) {
          if (pr[x][y] == '.') {
            addedge(id[0][i][j], id[0][x][y], 0);
          }
        }
      }
    }
  }
  int s = id[0][x1 - 1][y1 - 1], t = id[0][x2 - 1][y2 - 1];
  dis.resize(E.size());
  for (int i = 0; i < int(E.size()); ++i) {
    dis[i] = +1e9;
  }
  dis[s] = 0;
  std::deque<int> q;
  q.push_back(s);
  while (!q.empty()) {
    int u = q.front();
    q.pop_front();
    for (auto [v, w] : E[u]) {
      if (v != -1) {
        if (w == 0) {
          if (dis[u] < dis[v]) {
            dis[v] = dis[u];
            q.push_front(v);
          }
        } else {
          if (dis[u] + 1 < dis[v]) {
            dis[v] = dis[u] + 1;
            q.push_back(v);
          }
        }
      }
    }
  }
  std::cout << dis[t] << '\n';
  std::cerr << "N = " << E.size() << ", M = " << M << '\n';
  return 0;
}